package map;

import java.util.Comparator;

import array.Array;
import set.Set;

public class Map<T,K> {

	private Array<T> dom;
	private Array<K> img;
	
	public Map(){
		dom = new Array<T>();
		img = new Array<K>();
	}
	
	public boolean  add(T x, K y){
		if((x != null)&&(y != null)){
			if((dom.has(x))||(img.has(y))){
			}else{
				dom.add(x);
				img.add(y);
				return true;
			}
		}
		return false;
	}
	
	public boolean remove (T x, K y){
		if((x != null)&&(y != null)){
			if((!dom.has(x))||(!img.has(y))){
			}else{
				dom.remove(x);
				img.remove(y);
				return true;
			}
		}
		return false;
	}
	
	public K getImage(T elem){
		int i = dom.getIndex(elem);
		if(i >= 0) return img.get(i);
		return null;
	}
	
	public T getDomim(K elem){
		int i = img.getIndex(elem);
		if(i >= 0) return dom.get(i);
		return null;	
	}
	
	public Set<K> getImageSet(){
		return new Set<K>(img);
	}
	
	public Set<T> getDomemSet(){
		return new Set<T>(dom);
	}
	
	public Set<K> getImageSet(Comparator<K> comp){
		return new Set<K>(img, comp);
	}
	
	public Set<T> getDomemSet(Comparator<T> comp){
		return new Set<T>(dom, comp);
	}
}
